using System;
using System.Diagnostics.Contracts;
using Charisma.MongoDb.Linq.Expressions;

namespace Charisma.MongoDb.Linq
{
  partial class Translator
  {
    public TranslatedQuery<TResult> Translate<TResult>()
    {
      Contract.Ensures(Contract.Result<TranslatedQuery<TResult>>() != null);

      var projection = (ProjectionExpression)Visit(context.Query);
      var materializer = MaterializationHelper<TResult>.BuildMaterializer(projection, context);
      return new TranslatedQuery<TResult>(materializer);
    }
  }
}